//
//  PPCreateAlbumUploadableImageView.m
//  pickpic
//
//  Created by Jinxiao on 8/30/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPAlbumContentImageView.h"

@interface PPAlbumContentImageView ()
@property (readwrite, nonatomic, strong) UIImageView *imageView;
@property (readwrite, nonatomic, strong) UIButton *deleteButton;
@property (readwrite, nonatomic, strong) UIControl *control;
@end

@implementation PPAlbumContentImageView

- (instancetype)init {
    self = [super init];

    self.clipsToBounds = NO;

    _imageView = [[UIImageView alloc] init];
    _imageView.backgroundColor = [UIColor colorWithRGBHex:0xf2f2f2];
    _imageView.clipsToBounds = YES;
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:_imageView];

    _control = [[UIControl alloc] init];
    _control.backgroundColor = [UIColor clearColor];
    [self addSubview:_control];

    _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _deleteButton.contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4);
    [_deleteButton setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    [_deleteButton sizeToFit];
    [self addSubview:_deleteButton];

    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _imageView.frame = CGRectMake(0, 6, self.width - 6, self.height - 6);

    _control.frame = self.bounds;
    
    _deleteButton.top = -6;
    _deleteButton.right = self.width + 4;
}

- (void)setArtwork:(PPAbstractArtwork *)artwork {
    _artwork = artwork;

    _imageView.artwork = artwork;
}

@end
